//
//  LPResouceRepeatTishiView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPResouceRepeatTishiView.h"

@interface LPResouceRepeatTishiView ()
/**    */
@property (strong, nonatomic) UILabel  *headLine;
/**  sure  */
@property (strong, nonatomic) UIButton  *sendButton;
/**  backview  */
@property (strong, nonatomic) UIView  *backView;

@end
@implementation LPResouceRepeatTishiView

- (instancetype)initWithFrame:(CGRect)frame array:(NSArray *)times
{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat backHeight = times.count * 25 * [UIScreen zj_screenHScale] + 50 * [UIScreen zj_screenHScale] + 90 * [UIScreen zj_screenHScale];
        [self addSubview:self.backView];
        CGFloat backWith = 0.0;
        for (int i = 0; i < times.count; i ++) {
            CGFloat titleWitdh = [CalculateLabelHeight CalculateLabelWidthWithString:times[i] font:15 * [UIScreen zj_textFontScale] height:20 * [UIScreen zj_screenHScale]].width;
            if (titleWitdh > backWith) {
                backWith = titleWitdh;
            }

        }
        
       self.backView.sd_layout.widthIs(backWith + 20 * [UIScreen zj_screenWScale])
        .centerXEqualToView(self)
        .centerYEqualToView(self)
        .heightIs(backHeight);
        
        [self.backView addSubview:self.headLine];
        self.headLine.sd_layout.topEqualToView(self.backView)
        .leftEqualToView(self.backView)
        .rightEqualToView(self.backView)
        .heightIs(50 * [UIScreen zj_screenHScale]);
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 51 * [UIScreen zj_screenHScale], self.backView.width, 1)];
        view.backgroundColor = [UIColor themeGrayColor];
        [self.backView addSubview:view];
        
        
        [self.backView addSubview:self.sendButton];
        self.sendButton.sd_layout.bottomSpaceToView(self.backView, 10 * [UIScreen zj_screenHScale])
        .centerXEqualToView(self.backView)
        .widthIs(80 * [UIScreen zj_screenWScale])
        .heightIs(35 * [UIScreen zj_screenHScale]);
        
        UIView *under = [UIView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self.backView addSubview:under];
        under.sd_layout.leftEqualToView(self).bottomSpaceToView(self.sendButton, 10).widthIs(self.backView.width).heightIs(1);
        
        
        for (int i = 0; i < times.count; i ++) {
            
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 65 * [UIScreen zj_screenHScale] + 25 * [UIScreen zj_screenHScale] * i, self.backView.width, 20 * [UIScreen zj_screenHScale])];
            label.text = times[i];
            label.textAlignment = NSTextAlignmentCenter;
            label.font = LYPFONT(15);
            if (i == 0 || i == times.count - 1) {
                label.textColor = [UIColor textGrayColor];
            }else{
                label.textColor = [UIColor zj_colorWithHexString:@"f24141"];
            }
            [self.backView addSubview:label];
            
        }
        
        
        
    }
    return self;
}



- (void)clickButton{
    if (self.delegate) {
        [self.delegate LPResouceRepeatTishRemove_view];
    }
    [self removeFromSuperview];
}
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    if (self.delegate) {
//        [self.delegate LPResouceRepeatTishRemove_view];
//    }
//    [self removeFromSuperview];
//}

- (UIView *)backView{
    if (!_backView) {
        _backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 6;
    }
    return _backView;
}

- (UILabel *)headLine{
    if (!_headLine) {
        _headLine = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label.text = @"友情提示";
            
            label;
        });
    }
    return _headLine;
}

- (UIButton *)sendButton{
    if (!_sendButton) {
        _sendButton = ({
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40 * [UIScreen zj_screenWScale],  40 * [UIScreen zj_screenHScale], self.width - 80 * [UIScreen zj_screenWScale], 50 * [UIScreen zj_screenHScale])];
            [button setTitle:@"确认" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
            button.titleLabel.font = LYPFONT(15);
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.layer.cornerRadius = 5;
            button.layer.masksToBounds = YES;
            button;
            
        });
    }
    return _sendButton;
}


@end
